package o2o.delivery.model.to;

import com.jinyou.utils.common.DateUtils;
import com.jinyouapp.common.utils.map.AMapModel;
import com.jinyouapp.common.utils.map.AMapUtils;
import o2o.dao.PO.order.ORDER_STATUS;
import o2o.dao.PO.order.OrderGoods;
import o2o.dao.PO.order.OrderInfo;
import o2o.dao.PO.order.OrderInfoGoods;
import o2o.dao.VO.order.OtherOrderInfoVO;

import java.text.ParseException;
import java.util.List;

/**
 * @author Jahnke【1029777564@qq.com】
 * @ClassName DeliveryOrderTO
 * @Description:
 * @date 2021/1/27 11:03
 * @Version 1.0
 */
public class ThridPlateDeliveryOrderTO {

    private String username;                // 用户帐号
    private Long shopId;                    // 店铺Id
    private String source;                  // 订单来源  mt:美团  elm:饿了么
    private String originOrderNo;           // 原始订单号 例如：美团号
    private String plateOrderNo;            // 第三方平台号码（例如麦芽田的订单号）
    private String orderCreateTime;
    private String orderAcceptTime;
    private Double orderPrice;
    private Double goodsPrice;

    /**********************收货信息*****************/
    private String endAddr;
    private String endName;
    private String endPhone;
    private String endPhone2;
    private double endLat;
    private double endLng;

    /**********************取货地址*****************/
    private String startAddr;
    private String startPhone;
    private String startName;
    private double startLat;
    private double startLng;

    private String callBack;
    private String sorts;
    private String note;
    private String goodsCount;
    private Long orderDeliveryTime;
    private List<OrderInfoGoods> goodsList;

    //========================================


    public List<OrderInfoGoods> getGoodsList() {
        return goodsList;
    }

    public void setGoodsList(List<OrderInfoGoods> goodsList) {
        this.goodsList = goodsList;
    }

    public Long getOrderDeliveryTime() {
        return orderDeliveryTime;
    }

    public void setOrderDeliveryTime(Long orderDeliveryTime) {
        this.orderDeliveryTime = orderDeliveryTime;
    }

    public OtherOrderInfoVO convertTOInfo() {
        OtherOrderInfoVO info = new OtherOrderInfoVO();
        info.setPreDayNo(Integer.parseInt(this.sorts));
        info.setUsername(this.getUsername());
        info.setOrderStatus(ORDER_STATUS.SHOP_SURE);
        try {
            info.setPayTime(DateUtils.sdfDateTime.get().parse(this.getOrderCreateTime()).getTime());        // 支付时间充当第三方配送的创建时间
        } catch (ParseException e) {
            e.printStackTrace();
        }
        long distance = AMapUtils.getDistance(this.getStartLat(), this.getStartLng(), this.getEndLat(), this.endLng);
        info.setDistance(distance / 1000.0);        // 单位转换为千米
        info.setPayType("underline");
        info.setCreateUser(this.getUsername()).setCreateTime(System.currentTimeMillis());

        // 购买人信息
        info.setToUser(this.getEndName()).setToAddress(this.endAddr).setToPhone(this.getEndPhone())
                .setToLat(this.getEndLat()).setToLng(this.getEndLng());
        AMapModel addressByLngAndLat = null;
        try {
            addressByLngAndLat = AMapUtils.getAddressByLngAndLat(this.getEndLat(), this.endLng);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (addressByLngAndLat != null) {
            info.setToProvince(addressByLngAndLat.getProvince()).setToCity(addressByLngAndLat.getCity()).setToCounty(addressByLngAndLat.getCounty());
        }
        info.setGoodsPrice(this.getGoodsPrice()).setTotalMoney(this.getOrderPrice());
        info.setDeliveryCallBack(this.getCallBack());

        return info;
    }

    // private List<DeliveryOrderGoodsTO> goodsList = new ArrayList<>();

    public String getUsername() {
        return username;
    }

    public ThridPlateDeliveryOrderTO setUsername(String username) {
        this.username = username;
        return this;
    }

    public Long getShopId() {
        return shopId;
    }

    public ThridPlateDeliveryOrderTO setShopId(Long shopId) {
        this.shopId = shopId;
        return this;
    }

    public String getSource() {
        return source;
    }

    public ThridPlateDeliveryOrderTO setSource(String source) {
        this.source = source;
        return this;
    }

    public String getOriginOrderNo() {
        return originOrderNo;
    }

    public ThridPlateDeliveryOrderTO setOriginOrderNo(String originOrderNo) {
        this.originOrderNo = originOrderNo;
        return this;
    }

    public String getOrderCreateTime() {
        return orderCreateTime;
    }

    public ThridPlateDeliveryOrderTO setOrderCreateTime(String orderCreateTime) {
        this.orderCreateTime = orderCreateTime;
        return this;
    }

    public String getOrderAcceptTime() {
        return orderAcceptTime;
    }

    public ThridPlateDeliveryOrderTO setOrderAcceptTime(String orderAcceptTime) {
        this.orderAcceptTime = orderAcceptTime;
        return this;
    }

    public Double getOrderPrice() {
        return orderPrice;
    }

    public String getStartPhone() {
        return startPhone;
    }

    public ThridPlateDeliveryOrderTO setStartPhone(String startPhone) {
        this.startPhone = startPhone;
        return this;
    }

    public ThridPlateDeliveryOrderTO setOrderPrice(Double orderPrice) {
        this.orderPrice = orderPrice;
        return this;
    }

    public Double getGoodsPrice() {
        return goodsPrice;
    }

    public ThridPlateDeliveryOrderTO setGoodsPrice(Double goodsPrice) {
        this.goodsPrice = goodsPrice;
        return this;
    }

    public String getEndAddr() {
        return endAddr;
    }

    public ThridPlateDeliveryOrderTO setEndAddr(String endAddr) {
        this.endAddr = endAddr;
        return this;
    }

    public String getEndName() {
        return endName;
    }

    public ThridPlateDeliveryOrderTO setEndName(String endName) {
        this.endName = endName;
        return this;
    }

    public String getEndPhone() {
        return endPhone;
    }

    public ThridPlateDeliveryOrderTO setEndPhone(String endPhone) {
        this.endPhone = endPhone;
        return this;
    }

    public String getEndPhone2() {
        return endPhone2;
    }

    public ThridPlateDeliveryOrderTO setEndPhone2(String endPhone2) {
        this.endPhone2 = endPhone2;
        return this;
    }

    public double getEndLat() {
        return endLat;
    }

    public ThridPlateDeliveryOrderTO setEndLat(double endLat) {
        this.endLat = endLat;
        return this;
    }

    public double getEndLng() {
        return endLng;
    }

    public ThridPlateDeliveryOrderTO setEndLng(double endLng) {
        this.endLng = endLng;
        return this;
    }

    public String getStartAddr() {
        return startAddr;
    }

    public ThridPlateDeliveryOrderTO setStartAddr(String startAddr) {
        this.startAddr = startAddr;
        return this;
    }

    public String getStartName() {
        return startName;
    }

    public ThridPlateDeliveryOrderTO setStartName(String startName) {
        this.startName = startName;
        return this;
    }

    public double getStartLat() {
        return startLat;
    }

    public ThridPlateDeliveryOrderTO setStartLat(double startLat) {
        this.startLat = startLat;
        return this;
    }

    public double getStartLng() {
        return startLng;
    }

    public ThridPlateDeliveryOrderTO setStartLng(double startLng) {
        this.startLng = startLng;
        return this;
    }

    public String getCallBack() {
        return callBack;
    }

    public ThridPlateDeliveryOrderTO setCallBack(String callBack) {
        this.callBack = callBack;
        return this;
    }

    public String getSorts() {
        return sorts;
    }

    public ThridPlateDeliveryOrderTO setSorts(String sorts) {
        this.sorts = sorts;
        return this;
    }

    public String getNote() {
        return note;
    }

    public ThridPlateDeliveryOrderTO setNote(String note) {
        this.note = note;
        return this;
    }

    public String getGoodsCount() {
        return goodsCount;
    }

    public ThridPlateDeliveryOrderTO setGoodsCount(String goodsCount) {
        this.goodsCount = goodsCount;
        return this;
    }

    public String getPlateOrderNo() {
        return plateOrderNo;
    }

    public ThridPlateDeliveryOrderTO setPlateOrderNo(String plateOrderNo) {
        this.plateOrderNo = plateOrderNo;
        return this;
    }

// public List<DeliveryOrderGoodsTO> getGoodsList() {
    //     return goodsList;
    // }
    //
    // public ThridPlateDeliveryOrderTO setGoodsList(List<DeliveryOrderGoodsTO> goodsList) {
    //     this.goodsList = goodsList;
    //     return this;
    // }
}
